package com.wtx.chapter03;

/**
 * @description: 冒泡排序
 * @author: wtx
 * @createDate: 2020/6/10
 */
public class BubbleSort {
    
    public static void sort(int[] array){

        int temp;
        for (int i = 0; i <= array.length-2; i++)
            for (int j = 0; j <= array.length-2-i; j++)
                if (array[j]>array[j+1]){
                    temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
    }

    public static void main(String[] args) {
        int[] arr = {10,20,5,8};
        BubbleSort.sort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }
}
